package com.wq.hadoop.workspace;

import com.wq.hadoop.workspace.map.SimpleMap;
import com.wq.hadoop.workspace.reduce.SimpleReduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

/**
 * @Author: wangqiang20995
 * @Date:2018/11/1
 * @Description:
 * @Resource:
 */
public class SimpleRelax extends Configured implements Tool {
    @Override
    public int run(String[] strings) throws Exception {

        Configuration configured = getConf();
        String[] otherArgs = new GenericOptionsParser(configured,strings).getRemainingArgs();


        Job job = new Job(configured,"PriceChange_JY");
        job.setJarByClass(SimpleRelax.class);

        FileInputFormat.addInputPath(job,new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath(job,new Path(otherArgs[1]));

        job.setMapperClass(SimpleMap.class);
        job.setReducerClass(SimpleReduce.class);

        job.setOutputFormatClass(TextOutputFormat.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        job.waitForCompletion(true);
        return job.isSuccessful() ? 0 : 1;
    }

    public static void main(String args[]) throws Exception {
        int flag = ToolRunner.run(new Configuration(),new SimpleRelax(),args);
        System.exit(flag);
    }
}
